import React, {Component} from 'react';
import {Text, ScrollView} from 'react-native';
import {WingBlank, Flex, Toast, WhiteSpace} from '@ant-design/react-native';
import {getMsgInfo} from '~/api/message';
import moment from 'moment';

export default class MessgeInfo extends Component {
    static navigationOptions = {
        title: '消息详情',
    };
    constructor(props) {
        super(props);
        this.state = {
            msg_id: this.props.navigation.getParam('msg_id'),
            view_state: this.props.navigation.getParam('view_state'),
            title: '',
            type: '系统消息',
            time: '',
            info: '',
        };
        getMsgInfo({
            msg_id: this.state.msg_id,
            view_state: this.state.view_state,
        }).then((r) => {
            if (r.code === 0) {
                this.setState({
                    title: r.data.Message,
                    time: r.data.ToDateTime,
                    info: r.data.Contents,
                });
                this.props.navigation.state.params.getList();
            } else {
                Toast.info('失败', 1);
            }
        });
    }
    render() {
        return (
            <ScrollView style={{flex: 1, backgroundColor: 'white'}}>
                <WingBlank>
                    <WhiteSpace />
                    <Flex justify="center">
                        <Text style={{fontSize: 20}}>{this.state.title}</Text>
                    </Flex>
                    <WhiteSpace />
                    <Flex justify="between">
                        <Text>{this.state.type}</Text>
                        <Text>{moment(this.state.time).format('YYYY.MM.DD HH:mm')}</Text>
                    </Flex>
                    <WhiteSpace size="xl" />
                    <Flex>
                        <Text>{this.state.info}</Text>
                    </Flex>
                    <WhiteSpace />
                </WingBlank>
            </ScrollView>
        );
    }
}
